package com.xmut.eduservice.controller;


import com.xmut.commonutils.R;
import com.xmut.eduservice.entity.AclUser;
import com.xmut.eduservice.service.AclUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author huangchaoqin
 * @since 2020-09-05
 */
@RestController
@RequestMapping("/eduservice/acl-user")
public class AclUserController {
    @Autowired
    private AclUserService aclUserService;

    @PostMapping("/login")
    @ResponseBody
    public R login(@RequestBody  AclUser aclUser) {
        String username = aclUser.getUsername();
        String password = aclUser.getPassword();
        AclUser message = aclUserService.ifLogin(username,password);
        if (message == null) {
            return R.error();
        } else  {
            System.out.println("student");
            return R.ok().data("message",message);
        }
    }

    @PostMapping("/getuser")
    @ResponseBody
    public R getUser(@RequestBody  AclUser aclUser) {
        String id = aclUser.getId();
        AclUser result = aclUserService.getById(id);
        if (result == null) {
            return R.error();
        } else  {
            System.out.println("student");
            return R.ok().data("list",result);
        }
    }


    @PostMapping("/updateuser")
    @ResponseBody
    public R updateUser(@RequestBody  AclUser aclUser) {
        aclUserService.updateById(aclUser);
        return R.ok();
    }
}

